﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Data.SqlClient;
using yunbo.Model.SM;
using yunbo.Repositorys.SMRepositorys;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace yunbo.Controllers.SMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class WLDBMXController : ControllerBase
    {
        WLDBMXRepository WLDBMXRepository=new WLDBMXRepository();
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPost("PostWLDBMX")]
        public IActionResult Postwldb(TJwldbmx tjwldbmx)
        {
            // 获取当前时间，并格式化为字符串
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string id = $"wldbmx{currentTime}{randomNumberString}";
            wldbmx wldbmx = new wldbmx()
            {
                wldbmx_code=id,
                wldb_code=tjwldbmx.wldb_code,
                wl_code=tjwldbmx.wl_code,
                wldbmx_wlmc=tjwldbmx.wldbmx_wlmc,
                wldbmx_wllx=tjwldbmx.wldbmx_wllx,
                wldbmx_ggxh=tjwldbmx.wldbmx_ggxh,
                wldbmx_sqdbsl=tjwldbmx.wldbmx_sqdbsl,
                kc_code=tjwldbmx.kc_code,
            };
            bool rs = WLDBMXRepository.Postwldbmx(wldbmx) > 0;
            return Ok(rs);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetFYwldb")]
        public IActionResult GetFYwldb(string code)
        {
            List<wldbmx> wldbmxs = WLDBMXRepository.Getwldbmx(code);
            return Ok(wldbmxs);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("Updatewldbmx")]
        public IActionResult Updatewldbmx(string code,int sl)
        {
            bool rs = WLDBMXRepository.Updatewldbmx(code,sl)>0;
            return Ok(rs);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        [HttpDelete("Deletewldbmx")]
        public bool Deletewldbmx(string code)
        {
            string sql = $"delete wms_wldbmx where wldbmx_code='{code}'";
            bool rs = WLDBMXRepository.Deletewldbmx(code)>0;
            return rs;
        }
    }
}
